package com.dw.etl.core.controller;

import javax.servlet.http.HttpServletRequest;

import com.dw.etl.common.base.BaseException;
import com.dw.etl.core.bean.vo.LayMsg;
import org.springframework.beans.factory.annotation.Autowired;
import  com.dw.etl.common.base.BaseResult;
import  com.dw.etl.common.constant.CommonResultConstant;
import com.dw.etl.core.api.MdMedPubfldService;
import com.dw.etl.core.bean.model.MdMedPubfld;
import org.springframework.util.StringUtils;
import  com.dw.etl.common.vo.PaginationVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * mdMedPubfld控制器
 * Created by hozeData on 2021/07/05.
 */
@RestController
@RequestMapping("/etl/mdMedPubfld/")
@Api(tags="元数据-公共字段管理")
@CrossOrigin(origins = "*", maxAge = 3600)
public class MdMedPubfldController {

    @Autowired
    MdMedPubfldService mdMedPubfldService;

    @ApiOperation(value="分页查询")
    @RequestMapping(value="findByPage", method=RequestMethod.GET)
    public LayMsg findByPage(String filter, Integer page, Integer limit) {
        PaginationVO<MdMedPubfld> pageVO = mdMedPubfldService.findPageByLike(filter, page, limit);
        return LayMsg.success().addCount(pageVO.getTotal()).addData(pageVO.getEntryList());
    }

    @ApiOperation(value="条件查询")
    @RequestMapping(value="findByModel", method=RequestMethod.GET)
    public LayMsg findByModel(String str) {
        List<MdMedPubfld> pageVO = mdMedPubfldService.findByModel(new MdMedPubfld());
        return LayMsg.success().addData(pageVO);
    }

    @ApiOperation(value="保存")
    @ApiImplicitParam(name="mdMedPutfd", value="实体", paramType="body", required=true, dataType="MdMedPutfd")
    @RequestMapping(value="save", method=RequestMethod.POST)
    public BaseResult save(@RequestBody MdMedPubfld mdMedPubfld, HttpServletRequest request)  {
        int num;
        if(StringUtils.isEmpty(mdMedPubfld.getIdPubfld())) {
            num = mdMedPubfldService.insertSelective(mdMedPubfld);
        } else {
            num = mdMedPubfldService.updateByIdSelective(mdMedPubfld);
        }
        return new BaseResult(CommonResultConstant.SUCCESS, num);
    }

    @ApiOperation(value="详情")
    @ApiImplicitParam(name="idPubfld", value="主键", paramType="query", required=true, dataType="String")
    @RequestMapping(value="getById", method=RequestMethod.GET)
    public BaseResult getById(String idPubfld, HttpServletRequest request) throws BaseException {
        if(StringUtils.isEmpty(idPubfld)){
            throw new BaseException("请选择要编辑的项");
        }
        MdMedPubfld mdMedPubfld = mdMedPubfldService.getById(idPubfld);
        return new BaseResult(CommonResultConstant.SUCCESS, mdMedPubfld);
    }

    @ApiOperation(value="根据主键删除")
    @ApiImplicitParam(name="idPubfld", value="主键", paramType="query", required=true, dataType="String")
    @RequestMapping(value="delete", method=RequestMethod.GET)
    public BaseResult delete(String idPubfld, HttpServletRequest request) throws BaseException {
        if(StringUtils.isEmpty(idPubfld)){
            throw new BaseException("请选择要删除的项");
        }
        int num = mdMedPubfldService.deleteById(idPubfld);
        return new BaseResult(CommonResultConstant.SUCCESS, num);
    }



}
